/*
 * @Author: HZK
 * @Date: 2020-08-19 17:14:55
 * @LastEditTime: 2020-08-24 16:04:48
 * @LastEditors: hanfengmi
 * @Description: 
 */
// Functor

class Container {
    static of (value) {
        return new Container(value)
    }

    constructor (value) {
        this._value = value
    }

    map (fn) {
        return Container.of(fn(this._value))
    }
}

const aa = Container.of([1,2,3,1,2,3]).map(x=>x)

console.log(123,aa._value)

// MayBe
class MayBe {
    static of (value) {
        return new MayBe(value)
    }

    constructor (value) {
        this._value = value
    }

    map (fn) {
        return  this.isNothing() ? MayBe.of(this._value) : MayBe.of(fn(this._value))
    }

    isNothing () {
        return this._value === null || this._value === undefined
    }
}

// const bb = MayBe.of('Hello World').map(x => x.toUpperCase())
const bb = MayBe.of(undefined).map(x => x.toUpperCase())

console.log(bb)

// Either 函子
